<?php
class admin_login extends controller{
	public function index(){
		global $CFG;
		$url=$CFG->config['base_url'];
		if(isset($_POST)){
			if(isset($_POST['log']) and isset($_POST['pwd'])){
				$checkIdAdmin=$this->model()->login($_POST['log'],$_POST['pwd']);
				$this->load->helper('url');
				
				if($checkIdAdmin){
					if(isset($_SESSION['admin'])) unset($_SESSION['admin']);
					if(isset($_SESSION['back_url'])){
						$url=$_SESSION['back_url'];
						unset($_SESSION['back_url']);
					}else $url.='product/admin';
					$_SESSION['admin']=$checkIdAdmin;
					if(isset($_POST['rememberme'])){
						setcookie("admin", $checkIdAdmin, time()+3600);
					}
				}else{					
					$url.='admin';
				}
			}
		}
		redirect($url);
	}
}